package org.xdq.volatile关键字;

import java.util.concurrent.TimeUnit;

public class Test {

    static class T1 extends Thread{
        volatile  int num = 1;

        @Override
        public void run() {

            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            num = 10;
            System.out.println("num="+num);

        }
    }

    public static void main(String[] args) {

        T1 t1 = new T1();
        t1.start();

        new Thread(()->{

            while(t1.num != 10){
                //System.out.println("t1.num="+t1.num);
            }
            System.out.println("OK");
        }).start();
    }


}
